home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: lynx.cs.washington.edu!xyu
- From: Xuri Yu <xyu@lynx.cs.washington.edu>
- Subject: data structure of quadtree
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- Sender: news@beaver.cs.washington.edu (USENET News System)
- Organization: Computer Science & Engineering, U of Washington, Seattle
- Message-ID: <Pine.ULT.3.91.960124115310.21999A-100000@lynx.cs.washington.edu>
- Mime-Version: 1.0
- X-Nntp-Posting-Host: lynx.cs.washington.edu
- Date: Wed, 24 Jan 1996 20:02:48 GMT
-
- Hello,
-
- I try to define the data structure of quadtree as follows:
-
- class quadnode {
- protected:
-
- struct subnode {
- float avgdata;
- quadnode *child[2];
-
- subnode() { for (int i=0; i<2; i++) child[i] = new quadnode[2]; }
- };
-
- union {
- float data;
- subnode *nextquad;
- };
-
- public:
- quadnode(subnode *quad = NULL): nextquad(quad) {}
- quadnode(float x): data(x) {}
-
- friend class quadtree;
- };
-
- class quadtree {
- protected:
- quadnode root;
- ...
- };
-
- The purpose of using 'union' is to save memory. The design doesn't work
- well. Could anyone solve this problem? Thanks a lot.
-
- Zuri
-